package controllers

import (
	"GoFind/helper"
	"GoFind/models"
)

// Operations about Users
type UserController struct {
	CommonController
}

var paramMap = map[string]string{
	"Phone":    "手机号",
	"Nickname": "昵称",
	"Password": "密码",
	"Email":    "邮箱号",
}

func (u *UserController) Register() {
	user := models.UserAccount{
		Phone:    u.GetString("phone"),
		Nickname: u.GetString("nickname"),
		Password: u.GetString("password"),
	}

	if msg := helper.ValidParams(&user, paramMap); msg != "" {
		u.Failed(1101, msg, "")
		return
	}
	uac := new(models.UserAccountModel)
	r := uac.CreateUser(user)
	if r {
		u.Success(user)
	} else {
		u.Failed(1101, "注册失败", "")
	}
}
